/*   time:2019-06-13 20:39:23*/
var e = require("utils/core.js");
App({
    onShow: function() {
        this.onLaunch()
    },
    onLaunch: function() {
        var t = this;
        wx.getSystemInfo({
            success: function(e) {
                "0" == e.model.indexOf("iPhone X") ? t.setCache("isIpx", e.model) : t.setCache("isIpx", "")
            }
        });
        var i = this;
        wx.getSystemInfo({
            success: function(e) {
                wx.setStorageSync("systemInfo", e);
                var t = e.windowWidth,
                    a = e.windowHeight;
                i.globalData.ww = t, i.globalData.hh = a
            }
        })
    },
    checkAuth: function() {
        var a = "/pages/message/auth/index",
            t = getCurrentPages(),
            i = t[t.length - 1],
            o = {
                params: i.options || null,
                url: i.route
            };
        if (o.params.hasOwnProperty("scene")) {
            var n = {}, s = decodeURIComponent(o.params.scene).split("&").shift().split("=");
            n.id = s[1], o.params = n
        }
        this.setCache("routeData", o);
        var r = this.getCache("userinfo");
        wx.getSetting({
            success: function(t) {
                t.authSetting["scope.userInfo"] && r ? e.get("member", {}, function(e) {
                    e.error && wx.redirectTo({
                        url: a
                    })
                }) : wx.redirectTo({
                    url: a
                })
            }
        })
    },
    requirejs: function(e) {
        return require("utils/" + e + ".js")
    },
    getConfig: function() {
        if (null !== this.globalData.api) return {
            api: this.globalData.api,
            approot: this.globalData.approot,
            appid: this.globalData.appid
        };
        var e = wx.getExtConfigSync();
        return this.globalData.api = e.config.api, this.globalData.approot = e.config.approot, this.globalData.appid = e.config.appid, e.config
    },
    getCache: function(e, t) {
        var a = +new Date / 1e3,
            i = "";
        a = parseInt(a);
        try {
            (i = wx.getStorageSync(e + this.globalData.appid)).expire > a || 0 == i.expire ? i = i.value : (i = "", this.removeCache(e))
        } catch (e) {
            i = void 0 === t ? "" : t
        }
        return i || ""
    },
    setCache: function(e, t, a) {
        var i = +new Date / 1e3,
            o = !0,
            n = {
                expire: a ? i + parseInt(a) : 0,
                value: t
            };
        try {
            wx.setStorageSync(e + this.globalData.appid, n)
        } catch (e) {
            o = !1
        }
        return o
    },
    removeCache: function(e) {
        var t = !0;
        try {
            wx.removeStorageSync(e + this.globalData.appid)
        } catch (e) {
            t = !1
        }
        return t
    },
    close: function() {
        this.globalDataClose.flag = !0, wx.reLaunch({
            url: "/pages/index/index"
        })
    },
    getSet: function() {
        var a = this;
        "" == a.getCache("cacheset") && setTimeout(function() {
            var t = a.getCache("cacheset");
            e.get("cacheset", {
                version: t.version
            }, function(e) {
                e.update && a.setCache("cacheset", e.data)
            })
        }, 10)
    },
    url: function(e) {
        e = e || {};
        var t, a, i = {}, o = this.getCache("usermid");
        for (var n in t = e.mid || "", a = e.merchid || "", o) void 0 !== o[n] && (i[n] = o[n]);
        "" != o ? ("" != o.mid && void 0 !== o.mid || (i.mid = t), "" != o.merchid && void 0 !== o.merchid || (i.merchid = a)) : (i.mid = t, i.merchid = a), this.setCache("usermid", i)
    },
    impower: function(t, a, i) {
        wx.getSetting({
            success: function(e) {
                e.authSetting["scope." + t] || wx.showModal({
                    title: "用户未授权",
                    content: "您点击了拒绝授权，暂时无法" + a + "，点击去设置可重新获取授权喔~",
                    confirmText: "去设置",
                    success: function(e) {
                        e.confirm ? wx.openSetting({
                            success: function(e) {}
                        }) : "route" == i ? wx.switchTab({
                            url: "/pages/index/index"
                        }) : "details" == i || wx.navigateTo({
                            url: "/pages/index/index"
                        })
                    }
                })
            }
        })
    },
    globalDataClose: {
        flag: !1
    },
    globalData: {
        appid: "wx62549813ad12327f",
        api: "https://www.bai918.com/app/ewei_shopv2_api.php?i=1",
      approot: "https://www.bai918.com/ewei_shopv2/",
        userInfo: null
    }
});